package com.example.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.pojo.Gongyingshang;
import com.example.pojo.Materialzhu;
import com.example.pojo.inquiry;
import com.example.service.cgxjbiz;
import com.example.vo.PageBean;
import com.example.vo.cgxjvo;
import com.example.vo.gysvo;

@Controller
@RequestMapping("/zjj")
public class cgxjaction {
	@Autowired
	cgxjbiz biz;
	
	@RequestMapping("cgxj")
	public String find(){
		 System.out.println("咿呀成功了哦!");
		return "cgxj";
	}
	
	@ResponseBody
	@RequestMapping("querybypage")
	public PageBean querybypage(int pagenum){
		return biz.querybypage(pagenum,1);
	} 
	
	@ResponseBody
	@RequestMapping("querybyid")
	public int querybyid(String id)
	{
		return biz.querybyid(id);	 	
	}
	
	@ResponseBody
	@RequestMapping("queryhistory")
	public List<cgxjvo> queryhistory(String customerid)
	{
		 List<cgxjvo> list=new ArrayList<cgxjvo>();
		 for (cgxjvo cgxjvo : biz.queryhistory(customerid)) {
			list.add(cgxjvo);
		 }
		 for (cgxjvo cgxjvo : biz.queryhistory1(customerid)) {
			list.add(cgxjvo);
		}
		 for (cgxjvo cgxjvo : biz.queryhistory2(customerid)) {
			list.add(cgxjvo);
		}
		return list;
		
	}
	
	@ResponseBody
	@RequestMapping("querywl")
	public List<Materialzhu> querybyid()
	{
		return biz.querywl();	 	
	}
	
	@ResponseBody
	@RequestMapping("querywlbyid")
	public List<Materialzhu> querywlbyid(String prodId)
	{
		return biz.querywlbyid(prodId);	 	
	}
	
	@ResponseBody
	@RequestMapping("querygys")
	public List<Gongyingshang> querygys()
	{
		return biz.querygys();	 	
	}
	
	@ResponseBody
	@RequestMapping("querygysbyid")
	public gysvo querygysbyid(String GYSid)
	{
		return biz.querygysbyid(GYSid);	 	
	}
	
	@RequestMapping("addxj")
	@ResponseBody
	public void addxj(@RequestBody inquiry in)
	{
		in.setValidDate(in.getValidDate().substring(0, 10));
	    in.setBilldate(in.getBilldate().substring(0,10)); 
		biz.addxj(in);	 
		System.out.println(in.toString());
		 
	}
	
	@ResponseBody
	@RequestMapping("updateshzt")
	public void updateshzt(String id)
	{
		 biz.updateshzt(id);
	}
	
	@ResponseBody
	@RequestMapping("updateshzt1")
	public void updateshzt1(String id)
	{
		 biz.updateshzt1(id);
	}
	
	@ResponseBody
	@RequestMapping("deletexj")
	public void deletexj(String billno)
	{
		System.out.println(billno);
		biz.deletexj(billno);	
	}
}
